<template>
  <div class="history-card">
    <van-nav-bar
      title="中西方历史对照"
      left-arrow
      @click-left="$emit('close')"
    />
    
    <div class="card-content" v-if="cardData">
      <div class="comparison-container">
        <div class="timeline-column china">
          <h2>中国历史</h2>
          <div class="timeline">
            <div v-for="(event, index) in cardData.chinaEvents" 
                 :key="'china-' + index" 
                 class="timeline-item">
              <div class="event-year">{{ event.year }}</div>
              <div class="event-content">
                <h3>{{ event.title }}</h3>
                <p>{{ event.description }}</p>
              </div>
            </div>
          </div>
        </div>
        
        <div class="timeline-column west">
          <h2>西方历史</h2>
          <div class="timeline">
            <div v-for="(event, index) in cardData.westEvents" 
                 :key="'west-' + index" 
                 class="timeline-item">
              <div class="event-year">{{ event.year }}</div>
              <div class="event-content">
                <h3>{{ event.title }}</h3>
                <p>{{ event.description }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="loading" v-else>
      <van-loading type="spinner" color="#6e8efb" size="24px">生成历史对照卡片中...</van-loading>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps({
  cardData: {
    type: Object,
    required: true
  }
});

defineEmits(['close']);
</script>

<style lang="scss" scoped>
.history-card {
  min-height: 100vh;
  background-color: #faf6f1;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.card-content {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.comparison-container {
  display: flex;
  gap: 40px;
  margin-top: 20px;
}

.timeline-column {
  flex: 1;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.timeline-column h2 {
  font-size: 24px;
  color: #2c3e50;
  margin-bottom: 24px;
  text-align: center;
  font-weight: bold;
  position: relative;
  padding-bottom: 12px;

  &::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: currentColor;
  }
}

.china h2 {
  color: #c0392b;
}

.west h2 {
  color: #2980b9;
}

.timeline {
  position: relative;
  padding-left: 30px;

  &::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ddd;
  }
}

.timeline-item {
  position: relative;
  margin-bottom: 30px;
  padding-left: 20px;

  &::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 0;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid currentColor;
  }
}

.china .timeline-item::before {
  border-color: #c0392b;
}

.west .timeline-item::before {
  border-color: #2980b9;
}

.event-year {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}

.china .event-year {
  color: #c0392b;
}

.west .event-year {
  color: #2980b9;
}

.event-content {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

  h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #2c3e50;
  }

  p {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
  }
}

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}

@media (max-width: 768px) {
  .comparison-container {
    flex-direction: column;
    gap: 20px;
  }
  
  .card-content {
    padding: 12px;
  }
  
  .timeline-column {
    padding: 16px;
  }
  
  .timeline-column h2 {
    font-size: 20px;
  }
  
  .event-year {
    font-size: 16px;
  }
  
  .event-content {
    h3 {
      font-size: 16px;
    }
    
    p {
      font-size: 13px;
    }
  }
}
</style> 